package za.org.jcicada.cfgmngr.impl;

import za.org.jcicada.cfgmngr.IPhysicalServer;
import za.org.jcicada.cfgmngr.impl.katcp.ConfigurationKatcpSerializer;
import za.org.jcicada.comms.IConnection;
import za.org.jcicada.comms.IKatcpSerializerStrategy;
import za.org.jcicada.comms.IMessageListener;
import za.org.jcicada.comms.impl.AcceptListenerBase;

/**
 * Cinns accept listener that accepts connections and ties them to a given
 * IPhysicalServer.
 * @author rcrida
 */
public class PhysicalAcceptListener extends AcceptListenerBase {

	/**
	 * IPhysicalServer implementation to delegate requests to.
	 */
	protected IPhysicalServer physicalServer;
	
	/**
	 * Create an accept listener that listens for clients and passes messages
	 * through to the given IPhysicalServer implementation.
	 */
	public PhysicalAcceptListener(IPhysicalServer physicalServer) {
		this.physicalServer = physicalServer;
	}
	
	/**
	 * Create messages listeners for new connections. Implements abstract
	 * from AcceptListenerBase.
	 * 
	 * @param connection New connection from client.
	 */
	public IMessageListener createListener(IConnection connection) {
		return new PhysicalMessaging(connection, physicalServer);
	}

	@Override
	public IKatcpSerializerStrategy getKatcpSerializerStrategy() {
		return new ConfigurationKatcpSerializer();
	}

}
